package com.mdl.common.lock;

import com.mdl.common.lock.redsession.DistributedLockAOP;
import com.mdl.common.lock.redsession.RedissonDistributedLock;
import com.mdl.common.lock.redsession.RedissonManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DistributedLockAutoConfiguration {
    @Bean
    public RedissonManager redissonManagerBean(@Value("${redisson.address}") String address,
                                               @Value("${redisson.password}") String password,
                                               @Value("${redisson.connectionPoolSize}") int connectionPoolSize,
                                               @Value("${redisson.idleConnectionTimeout}") int idleConnectionTimeout,
                                               @Value("${redisson.connectTimeout}") int connectTimeout,
                                               @Value("${redisson.timeout}") int timeout,
                                               @Value("${redisson.pingTimeout}") int pingTimeout,
                                               @Value("${redisson.reconnectionTimeout}") int reconnectionTimeout) {
        return new RedissonManager(address, password, connectionPoolSize, idleConnectionTimeout, connectTimeout, timeout, pingTimeout, reconnectionTimeout);
    }

    @Bean
    public RedissonDistributedLock RedissonDistributedLockBean(RedissonManager redissonManager) {
        return new RedissonDistributedLock(redissonManager);
    }

    @Bean
    public DistributedLockAOP DistLockerAOPBean() {
        return new DistributedLockAOP();
    }
}
